import 'package:flutter/material.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/public/public_keyBoardActions.dart';

class MGCard extends StatelessWidget {
  /// 排序方式
  final MainAxisAlignment mainAxisAlignment;

  /// 排序方式
  final CrossAxisAlignment crossAxisAlignment;

  /// 偏移 【默认周围16】
  final EdgeInsetsGeometry? padding;

  /// 外偏移【默认0】
  final EdgeInsetsGeometry? margin;

  /// 背景色
  final Color? backColor;

  /// Widget
  final List<Widget>? children;

  final List<FocusNode>? nodeList;

  /// 点击事件
  final Function()? action;

  final double radius;

  const MGCard({
    super.key,
    this.padding,
    this.margin,
    this.action,
    this.nodeList,
    this.mainAxisAlignment = MainAxisAlignment.start,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.backColor,
    this.children,
    this.radius = 8,
  }) : assert((children != null && children.length > 0));

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: (nodeList != null && nodeList!.isNotEmpty)
          ? HLKeyBoardActions.keyboardActionsWidget(
              list: nodeList!,
              child: Column(
                children: [
                  Container(
                    padding: padding ?? EdgeInsets.all(16),
                    margin: margin,
                    width: double.infinity,
                    decoration: BoxDecoration(
                      color: backColor ?? MGColors.whileColor,
                      borderRadius: BorderRadius.circular(radius),
                    ),
                    child: Column(
                      children: children ?? [],
                      mainAxisAlignment: mainAxisAlignment,
                      crossAxisAlignment: crossAxisAlignment,
                      mainAxisSize: MainAxisSize.min,
                    ),
                  )
                ],
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
              ))
          : Container(
              padding: padding ?? EdgeInsets.all(12),
              margin: margin,
              width: double.infinity,
              decoration: BoxDecoration(
                color: backColor ?? MGColors.whileColor,
                borderRadius: BorderRadius.circular(radius),
              ),
              child: Column(
                children: children ?? [],
                mainAxisAlignment: mainAxisAlignment,
                crossAxisAlignment: crossAxisAlignment,
                mainAxisSize: MainAxisSize.min,
              ),
            ),
      onTap: action,
    );
  }
}
